from . import db
import datetime

class MoocGrade(db.Model):
    __tablename__ = 'mooc_grades'
    """年级"""
    id = db.Column(db.BigInteger, primary_key=True)
    name = db.Column(db.String(255), comment="名称")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class MoocUclass(db.Model):
    __tablename__ = 'mooc_uclasses'
    """班级列表"""
    id = db.Column(db.BigInteger, primary_key=True)
    name = db.Column(db.String(255), comment="名称")
    class_type = db.Column(db.String(255), comment="班级类型, ")
    grade_id = db.Column(db.BigInteger, default=0, comment="年级id")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class MoocUclassUser(db.Model):
    __tablename__ = 'mooc_uclass_users'
    """班级用户关联列表"""
    id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.Integer, comment="用户id")
    uclass_id = db.Column(db.BigInteger, default=0, comment="班级id")
    uclass_role = db.Column(db.SmallInteger, default="student", comment="班级角色, student: 学生, teacher：教师")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class MoocSubject(db.Model):
    """课程类型"""
    __tablename__ = 'mooc_subjects'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), unique=True, nullable=False, comment='课程类型')
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)


class OffilneCourse(db.Model):
    __tablename__ = 'offline_courses'
    """线下课程"""
    id = db.Column(db.BigInteger, primary_key=True)
    name = db.Column(db.String(255), nullable=False, comment="课程名称")
    create_type = db.Column(db.String(125), default="original", comment="课程类型 original:原创 collection:收藏")
    class_hours = db.Column(db.Float, default=0, comment="建议课时")
    apply_grade_ids = db.Column(db.String(255), comment="适用年级 例如1,2,3")
    mooc_subject_id = db.Column(db.BigInteger, comment="课程分类id 例如: 平台课程分类id, 本地课程分类id")
    cover_url = db.Column(db.String(255), comment="课程封面图")
    introduction_video_url = db.Column(db.String(255), comment="课程简介视频")
    description = db.Column(db.Text, comment="课程简介")
    implementation = db.Column(db.Text, comment="实施条件")
    instructional_design = db.Column(db.Text, comment="教学设计")
    price = db.Column(db.Float, default=0, comment="课程价格 默认为0,免费")
    author_user_id = db.Column(db.BigInteger, comment="创建者id,课程类型为创建时为创建者id，收藏时为被收藏课程的offline_enrollment的user_id")
    original_course_id = db.Column(db.BigInteger, comment="原创课程id")
    collection_user_id = db.Column(db.BigInteger, comment="收藏者id")
    status = db.Column(db.String(125), default="unpublished", comment="课程状态 unpublished:未发布 published:发布 deleted:删除")
    college_id = db.Column(db.BigInteger, default=1, comment="机构id")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class OffilneCourseEnrollment(db.Model):
    __tablename__ = 'offline_course_enrollments'
    """用户线下课程关联表"""
    id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.BigInteger, nullable=False, comment="用户id")
    offline_course_id = db.Column(db.BigInteger, nullable=False, comment="线下课程id")
    relation_type = db.Column(db.String(125), nullable=False, comment="用户线下课程关系 teacher:老师 student:学生")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class OfflineCourseFile(db.Model):
    __tablename__ = 'offline_course_files'
    """线下课程文件表"""
    id = db.Column(db.BigInteger, primary_key=True)
    title = db.Column(db.String(255), nullable=False, comment="文件名称")
    size = db.Column(db.String(255), nullable=False, comment="文件名称")
    file_type = db.Column(db.String(125), nullable=False, comment="文件类型 ppt word excle之类")
    offline_course_id = db.Column(db.BigInteger, nullable=False, comment="线下课程id")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class StudentWork(db.Model):
    __tablename__ = 'student_works'
    """学生作品"""
    id = db.Column(db.BigInteger, primary_key=True)
    title = db.Column(db.String(255), nullable=False, comment="作品名称")
    work_type = db.Column(db.String(255), nullable=False, comment="作品类型 text:文字  picture:图片  video:视频")
    content = db.Column(db.String(255), nullable=False, comment="作品内容")
    user_id = db.Column(db.BigInteger, nullable=False, comment="用户id")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class ThumbsUp(db.Model):
    __tablename__ = 'thumbs_ups'
    """点赞表"""
    id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.BigInteger, nullable=False, comment="点赞用户id")
    student_work_id = db.Column(db.BigInteger, nullable=False, comment="被点赞的学生作品id")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

class Comment(db.Model):
    __tablename__ = 'comments'
    """评论表"""
    id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.BigInteger, nullable=False, comment="评论者用户id")
    student_work_id = db.Column(db.BigInteger, nullable=False, comment="被点赞的学生作品id")
    pid = db.Column(db.BigInteger, default=0, comment="被评论的评论的id, 默认评论作品,为0")
    content = db.Column(db.Text, comment="内容")
    status = db.Column(db.String(125), default="active", comment="状态 active:正常 deleted:删除")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now)

